package team.se.tms.util;

import javax.servlet.http.HttpServletRequest;

/**
 * 获取路径工具类
 *
 * @author winkyle
 * @date 2018/11/27
 */
public class PathUtil {

    /**
     * 获取服务器的访问路径;协议名称://服务器名称:端口/web项目
     *
     * @param httpServletRequest HttpServletRequest对象
     * @return 服务器的访问路径
     * @create on 2018/11/27 by winkyle
     */
    public static String getAccessPath(HttpServletRequest httpServletRequest){
        return httpServletRequest.getScheme()+"://"+httpServletRequest.getServerName()+":"+
                httpServletRequest.getServerPort()+httpServletRequest.getContextPath()+"/";
    }

    /**
     * 获取web项目的绝对路径
     *
     * @param httpServletRequest HttpServletRequest对象
     * @return web项目的绝对路径
     * @create on 2018/11/27 by winkyle
     */
    public static String getAbsolutePath(HttpServletRequest httpServletRequest){
        return httpServletRequest.getSession().
                getServletContext().getRealPath("/");
    }
}
